package algotithm.jianzhioffer.test28;


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    public TreeNode(int val) {
        this.val = val;
    }
}
/**
 * @author zhouyanxiang
 * @Date 2020-12-2020/12/29-15:25
 */
public class Solution {

    public static void main(String[] args) {
        TreeNode node1 = new  TreeNode(1);
        TreeNode node2 = new  TreeNode(2);
        TreeNode node3 = new  TreeNode(2);
        TreeNode node4 = new  TreeNode(3);
        TreeNode node5 = new  TreeNode(4);
        TreeNode node6 = new  TreeNode(4);
        TreeNode node7 = new  TreeNode(10);
        node1.left = node2;
        node1.right = node3;
        node2.left = node4;
        node2.right = node5;
        node3.left = node6;
        node3.right = node7;
        node4.left = null;
        node4.right = null;
        node5.left = null;
        node5.right = null;
        node6.left = null;
        node6.right = null;
        node7.left = null;
        node7.right = null;

        Solution solution = new Solution();
        boolean symmetric = solution.isSymmetric(node1);
        System.out.println(symmetric);
    }

    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return recur(root.left,root.right);
    }

    public boolean recur(TreeNode L,TreeNode R) {
        if (L == null && R == null) {
            return true;
        }
        if (L == null || R == null || L.val != R.val) {
            return false;
        }
        return recur(L.left,R.right) && recur(L.right, R.left);
    }

}
